package com.ruoyi.web.wh.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.Log;
import com.ruoyi.framework.enums.BusinessType;
import com.ruoyi.web.wh.domain.WhStorage;
import com.ruoyi.web.wh.service.IWhStorageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.Result;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 仓库Controller
 *
 * @author ruoyi
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/wh/storage")
public class WhStorageController extends BaseController {
    @Autowired
    private IWhStorageService whStorageService;

    /**
     * 查询仓库列表
     */
    @SaCheckPermission("wh:storage:list")
    @GetMapping("/list")
    public TableDataInfo list(WhStorage whStorage) {
        startPage();
        List<WhStorage> list = whStorageService.selectWhStorageList(whStorage);
        return getDataTable(list);
    }


    /**
     * 获取仓库详细信息
     */
    @SaCheckPermission("wh:storage:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(whStorageService.selectWhStorageById(id));
    }

    /**
     * 新增仓库
     */
    @SaCheckPermission("wh:storage:add")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody WhStorage whStorage) {
        return toAjax(whStorageService.insertWhStorage(whStorage));
    }

    /**
     * 修改仓库
     */
    @SaCheckPermission("wh:storage:edit")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody WhStorage whStorage) {
        return toAjax(whStorageService.updateWhStorage(whStorage));
    }

    /**
     * 删除仓库
     */
    @SaCheckPermission("wh:storage:remove")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(whStorageService.deleteWhStorageByIds(ids));
    }
}
